using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.ObjectBuilder;
using Jbe.TestSuite.Infrastructure.Interface;
using Jbe.TestSuite.Infrastructure.Module.Services;
using Jbe.TestSuite.Infrastructure.Interface.Services;
using Jbe.TestSuite.Infrastructure.Module.EditAdapters;
using SCSFContrib.CompositeUI.WinForms;

namespace Jbe.TestSuite.Infrastructure.Module
{
    public class Module : ModuleInit
    {
        private WorkItem rootWorkItem;
        private IAdapterFactoryCatalog<IEditHandler> factoryCatalog;

        [InjectionConstructor]
        public Module([ServiceDependency] WorkItem rootWorkItem)
        {
            this.rootWorkItem = rootWorkItem;
        }

        public override void AddServices()
        {
            rootWorkItem.Services.AddNew<WinFormsCreationService, IUIElementCreationService>();
            rootWorkItem.Services.AddOnDemand<DocumentManager, IDocumentManager>();
            factoryCatalog = rootWorkItem.Services.AddNew<AdapterFactoryCatalog<IEditHandler>, IAdapterFactoryCatalog<IEditHandler>>();
            rootWorkItem.Services.AddNew<EditManager, IEditManager>();
        }

        public override void Load()
        {
            factoryCatalog.RegisterFactory(new TextBoxAdapterFactory());
        }
    }
}
